﻿using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameName1
{
    class Arena : GameComponent
    {
        private Texture2D _black;
        private Texture2D _white;
        Vector2 _positionPixel;
        private float _outerRadiusPixel = 360;
        private float _innerRadiusPixel = 300;
        private float _outerRadius;
        private float _innerRadius;
        private Vector2 _innerOrigin;
        private Vector2 _outerOrigin;
        public Arena(Game game, World world, Vector2 initialPositionSim)
            :base(game, initialPositionSim, world )
        {
            _black = Game.Content.Load<Texture2D>("doyo1");
            _white = Game.Content.Load<Texture2D>("doyo2");
            _positionPixel = ConvertUnits.ToDisplayUnits(initialPositionSim);
            _innerOrigin = new Vector2(_innerRadiusPixel / 2, _innerRadiusPixel / 2);
            _outerOrigin = new Vector2(_outerRadiusPixel / 2, _outerRadiusPixel / 2);
            _innerRadius = ConvertUnits.ToSimUnits(_innerRadiusPixel);
            _outerRadius = ConvertUnits.ToSimUnits(_outerRadiusPixel);
        }

        public override void Draw(GameTime gameTime, SpriteBatch batch)
        {
            Rectangle rInner = new Rectangle((int)(_positionPixel.X - _innerRadiusPixel), (int)(_positionPixel.Y - _innerRadiusPixel), (int)(2 * _innerRadiusPixel), (int)(2 * _innerRadiusPixel));
            Rectangle rOuter = new Rectangle((int)(_positionPixel.X - _outerRadiusPixel), (int)(_positionPixel.Y - _outerRadiusPixel), (int)(2 * _outerRadiusPixel), (int)(2 * _outerRadiusPixel));
            // Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effect, float depth);
            batch.Draw(_white, rOuter, null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f);
            batch.Draw(_black, rInner, null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f);
            
        }
        public bool BelongsToMargin(Vector2 pointSim)
        {
            float y2 = (pointSim.X-InitialPositionSim.X)*(pointSim.X-InitialPositionSim.X)+
                (pointSim.Y-InitialPositionSim.Y)*(pointSim.Y-InitialPositionSim.Y);
   
            if ((y2 > _innerRadius * _innerRadius) && (y2 < _outerRadius * _outerRadius))
            {
                return true;
            }
            return false;
        }
    }
}
